﻿using Microsoft.EntityFrameworkCore.Migrations;

namespace EfCoreDemo.Data.Migrations
{
    public partial class addViewAndProduce : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.Sql(@"
create view [dbo].[PlayserClubView] 
as 
select p.Id as PlayerId,p.name as PlayerName,c.Name as ClubName 
from [dbo].[Players] as p 
inner join [dbo].[Clubs] as c 
on p.ClubId=c.Id");
            
            migrationBuilder.Sql(@"
create procedure [dbo].[RemoveGamePlayerProcedure] 
@playerId int=0 
as 
delete from [dbo].[GamePlayer] where [PlayerId]=@playerId 
return 0");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            //回滚顺序应该和up 顺序相反
            migrationBuilder.Sql(@"drop procedure [dbo].[RemoveGamePlayerProcedure]");
            migrationBuilder.Sql(@"drop view [dbo].[PlayserClubView]");
        }
    }
}
